<?php 
	session_start();
	error_reporting(0);
?>
<!DOCTYPE HTML>
<html>
	<head>
		<title>
			Management
		</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" />
		<meta http-equiv="x-ua-compatible" content="IE=edge">
		<link type="text/css" href="CSS/jquery-ui-1.10.3.custom.min.css" rel="stylesheet"/>
		<link type="text/css" href="CSS/ui.jqgrid.css" rel="stylesheet"/>
		<link type="text/css" href="CSS/jquery.multiselect.css" rel="stylesheet"/>
		<link type="text/css" href="CSS/stylesheet.css" rel="stylesheet" media="screen"/>
		<link type="text/css" href="CSS/new-css.css" rel="stylesheet"/>
		<script type="text/javascript" src="Javascript/jquery-2.0.3.min.js"></script>
		<script type="text/javascript" src="Javascript/jquery-ui-1.10.3.custom.min.js"></script>
		<script type="text/javascript" src="Javascript/jquery.jqGrid.min.js"></script>
		<script type="text/javascript" src="Javascript/grid.locale-en.js"></script>
		<script type="text/javascript" src="Javascript/menu.js"></script>
		<script type="text/javascript" src="Javascript/jquery.multiselect.min.js"></script>
		<script type="text/javascript">
			$(document).ready(function(){
				$("#login").click(
					function(e){
						e.preventDefault();
						// Logout
						if($("#login>span").text().search("out") > -1){
							$.ajax({
								url: "log-out.php",
								method: "POST",
								success: function(res){
									$("#login>span").text("Log in");
									$("._k_will_be_hidden").show();
									jQuery("#list2").html("");
								}
							});	
							return;
						}
						// Login
						var adminname = $("#_k_admin_name").val();
						var adminpsw = $("#_k_admin_psw").val();
						if(adminname === "" || adminpsw === ""){
							alert("Please enter both name and password to login.");
							return;
						}
						$.ajax({
							url: "login-action.php",
							dataType: "json",
							type: "POST",
							data: {adminname: adminname,adminpsw: adminpsw},
							success: function(response){
								if(response != null && response.result === "failed") {
									alert("Login failed.");
									$("#_k_admin_name").focus();
									return;
								}
								//hide texboxes
								$("#login>span").text("Log out");
								$("._k_will_be_hidden").hide();
								$("#_k_welcome>span").text("Welcome back, admin.");
								//end
								$.ajax({
									url: "get-data.php",
									dataType: "json",
									type:"POST",
									success: function(response){
										var mydata = response; 										
										
									},
									error: function(d){
										alert("Login failed");
									}
								});
							},
							error: function(data){								
								alert(data);
							}
						});
						
					}		
				);
			});
		</script>
	</head>
	<body>
		<div id="container">
			<div id="header">
				<div class="topHeader">
					<div class="top-left-Header">
						<img alt="LOGO" src="Images/logo.png" width="180" height="29" class="logo"/>
					</div>
					<div class="top-right-Header">
						<ul><?php if(!isset($_SESSION['admin'])){?>
							<li id="_k_welcome">
								<span style="font-weight: bold; color: #e9e9e9"></span>
							</li>
							<li class="_k_will_be_hidden">
								<span style="font-weight: bold; color: #e9e9e9">Account: </span>
								<input type="text" name="userName" placeholder="admin name" id="_k_admin_name"/></li>
							<li class="_k_will_be_hidden">
								<span style="font-weight: bold; color: #e9e9e9">Password: </span>
								<input type="password" name="password" placeholder="password" id="_k_admin_psw"/>
							</li>
							<?php }
								else{
							?>
							<li id="_k_welcome">
								<span style="font-weight: bold; color: #e9e9e9">Welcome back, admin!</span>
							</li>
							<?php }?>
							<li>
								<button id="login">
									<span class="button">
										<?php if(!isset($_SESSION['admin'])){
											echo "Log in";
											
										}else echo ("Log out");?>
									</span>
								</button>
							</li>
						</ul>
					</div>
				</div>
				<div class="botton-header"></div>
			</div>
			<div id="content">
				<div class="left-content">
			</div>
				<div class="right-content">
					<div class="title">
						<div class="left-title">
							User Management
						</div>
					
					</div>
					<div class="wrapper">
						<div class="main-wrapper">
							<table id="_k_list2" class="bordered">
								<thead>
								    <tr>
								        <th>ID</th>        
								        <th>Name</th>
								        <th>Email</th>
								        <th>Phone Number</th>
								        <th>Total Point</th>
								        <th></th>
								        <th></th>
								    </tr>
								    <tr>
								    	<td class="_id">1</td>
								    	<td class="_name">Khương Đào</td>
								    	<td class="_email">songokute@live.com</td>
								    	<td class="_phone">098765432</td>
								    	<td class="_total_point">90</td>
								    	<td><a href="#" class="_view">View</a></td>
								    	<td><a href="#" class="_delete">Delete</a></td>
								    </tr>
							    </thead>
							</table> 
							<div id="pager2"></div>
							<script type="text/javascript">
								//jQuery grid
								
									
							</script>
							<div class="container-button">
							</div>
						</div>
					</div>
				</div>
				<div id="footer">
					<div class="content-footer">
						Copyright &copy; AnhND
					</div>
					
				</div>
				<div style="clear: both;"></div>
		</div>
	</body>
</html>